package com.heima.wemedia.controller.v1;

import com.heima.common.dtos.PageResponseResult;
import com.heima.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmMaterial;
import com.heima.wemedia.dto.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/v1/material")
public class WmMaterialController {

    @Resource
    private WmMaterialService wmMaterialService;

    @PostMapping("/upload_picture")
    public ResponseResult<WmMaterial> uploadPicture(@RequestParam("multipartFile") MultipartFile multipartFile) {
        return this.wmMaterialService.uploadPicture(multipartFile);
    }

    /**
     * 素材列表查询
     */
    @PostMapping("/list")
    public PageResponseResult<List<WmMaterial>> findList(@RequestBody WmMaterialDto dto) {
        return this.wmMaterialService.findList(dto);
    }

    @GetMapping("del_picture/{id}")
    public ResponseResult<String> deleteImage(@PathVariable("id") Integer id) {
        boolean result = this.wmMaterialService.deleteImage(id);
        if (result) {
            return ResponseResult.okResult(200, "操作成功");
        }
        return ResponseResult.errorResult(501, "文件删除失败");
    }

    @GetMapping("cancle_collect/{id}")
    public ResponseResult<String> changeStatus(@PathVariable("id") Integer id) {
        boolean result = this.wmMaterialService.changeStatus(id);
        if (result) {
            return ResponseResult.okResult(200, "操作成功");
        }
        return ResponseResult.errorResult(501, "参数失效");
    }
}




















